package com.bwie.service.impl;

import com.bwie.common.domain.Role;
import com.bwie.common.domain.User;
import com.bwie.mapper.SysUserMapper;
import com.bwie.service.SysUserServcie;
import com.google.common.hash.BloomFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @className: SysUserServcieImpl
 * @Description: TODO
 * @version: v1.８.0
 * @author: 汪菲阳
 * @date: 2025/10/22 9:44
 */
@Service
public class SysUserServcieImpl implements SysUserServcie {
    @Autowired
    private SysUserMapper sysUserMapper;
    @Autowired
    private BloomFilter<String> filter;
    @Autowired
    private BCryptPasswordEncoder bCryptPasswordEncoder;

    @Override
    public User selectUserByUserPhone(User user) {
        return sysUserMapper.selectUserByUserPhone(user);
    }

    @Override
    public List<Role> selectRoleByUserId(Integer userId) {
        return sysUserMapper.selectRoleByUserId(userId);
    }

    @Override
    public void registerUser(User user) {
        //获取手机号
        String userPhone = user.getUserPhone();
        //用户手机号唯一性校验
        filter.mightContain(userPhone);
        //给用户名称以及密码初始化
        user.setUserName("admin");
        user.setUserPassword("123456");
        //进行密码加密
        bCryptPasswordEncoder.encode(user.getUserPassword());
        //添加用户
        sysUserMapper.registerUser(user);
    }
}
